1. Field of the Invention
The present invention relates to operating systems for computers. More specifically, the present invention relates to a method and an apparatus that uses a shared library mechanism to facilitate sharing metadata, such as classes or compiled methods, between multiple instances of a language run-time system.
2. Related Art
It is often advantageous to share metadata, such as class files or dynamically compiled code, across multiple instances of a runtime system of a programming language, such as the Java Virtual Machine (JVM™). (The terms “Sun Microsystems”, “Java”, “Java virtual machine” and “JVM” are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.)
Sharing of metadata across multiple instances of a language runtime system can be accomplished by storing the metadata in a shared memory area. However, unless the metadata is read-only, such sharing means that there will exist periods of time when the shared memory area will be accessible for writing by the sharing processes. In some situations this does not create a problem. However, a bug in one of the instances or in a user-supplied native library may lead to uncontrolled writing in the shared memory area. This may cause the shared memory area to be corrupted for all processes, not just for the process that actually corrupted the shared memory area.
Another problem with using shared memory is that updates to the shared memory area have to be guarded by a concurrency control primitive, such as a monitor or a semaphore. If a process making an update (e.g., adding another piece of metadata) unexpectedly terminates during the update, the system must ensure that the relevant concurrency control objects are released in order to avoid preventing other processes from using the shared memory area.
Despite these challenges, sharing of metadata remains attractive because of its potential to decrease the memory footprint of virtual machines and to factor out costs related to on-demand class loading (e.g., parsing, verification, dynamic link resolution) and to architecture neutrality of class files (e.g., runtime quickening of interpreted code and runtime compilations).
What is needed is method and an apparatus that facilitates sharing of metadata between multiple virtual machines and/or processes in a manner that efficiently deals with the above-described challenges.